/*
 * @Author: kls
 * @Date: 2023-08-04 09:12:06
 * @LastEditTime: 2023-08-04 10:43:05
 * @LastEditors: kls
 * @Description: 
 * @FilePath: \jnks-drone-company\src\stores\mqttInfo.js
 */
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import storage from 'storejs'

export const useDroneStore = defineStore('droneStore', () => {
  const droneDatestate = ref({
    droneDate: storage.get('droneDate') || '', //  当前无人机信息
  })
  const droneGroupstate = ref({
    droneGroupList: storage.get('droneGroupList') || [],
  })
  const uavflynowdatastate = ref({
    uavflynowdata: [], // 当前在飞的无人机droneCode
  })
  const newflystate = ref({
    newfly: 0, // 无人机起飞标识
  })
  const newonpenDevicestate = ref({
    onpenDevice: 0, //有没有设备开启状态
  })

  const setDroneDate = (payload) => {
    droneDatestate.value.droneDate = payload
    storage.set('droneDate', payload)
  }
  const setDroneGroup = (payload) => {
    droneGroupstate.value.droneGroupList = payload
  }
  const setUavflynowdata = (payload) => {
    uavflynowdatastate.value.uavflynowdata = payload
    storage.set('uavflynowdata', payload)
  }
  const setnewfly = (payload) => {
    newflystate.value.newfly++
  }
  const setonpenDevice = (payload) => {
    newonpenDevicestate.value.newfly++
  }
  const cacheDroneDatestate = computed(() => droneDatestate)
  return {
    droneDatestate,
    droneGroupstate,
    uavflynowdatastate,
    cacheDroneDatestate,
    newflystate,
    newonpenDevicestate,
    setDroneDate,
    setDroneGroup,
    setUavflynowdata,
    setnewfly,
    setonpenDevice
  }
})
